<script src="Libraries/js/js.js"></script>
<script language="javascript">
   function rangBuoc(){
   		 document.xemnhatki.cbohocki.selectedIndex=0;
   }
   function getValue(id){
        /*for(var i=0;i<document.xepthoikhoabieu.cbohocki.length;i++){
    		if(document.xepthoikhoabieu.cbohocki[i].value==document.getElementById("hocki" + id).innerHTML){
    			document.xepthoikhoabieu.cbohocki.selectedIndex=i;
    		}
    	}
        for(var i=0;i<document.xepthoikhoabieu.cbonamhoc.length;i++){
    		if(document.xepthoikhoabieu.cbonamhoc[i].value==document.getElementById("namhoc" + id).innerHTML){
    			document.xepthoikhoabieu.cbonamhoc.selectedIndex=i;
    		}
    	}*/
		for(var i=0;i<document.xepthoikhoabieu.cbohp.length;i++){
    		if(document.xepthoikhoabieu.cbohp[i].value==document.getElementById("mahp" + id).innerHTML){
    			document.xepthoikhoabieu.cbohp.selectedIndex=i;
    		}
    	}
		for(var i=0;i<document.xepthoikhoabieu.cbotietbd.length;i++){
    		if(document.xepthoikhoabieu.cbotietbd[i].value==document.getElementById("tietbd" + id).innerHTML){
    			document.xepthoikhoabieu.cbotietbd.selectedIndex=i;
    		}
    	}
        
    	//document.capnhathpmovaohknh.txtmahp.value=document.getElementById("mahp" + id).innerHTML;
	
	
}
</script>
<?php
	include_once('Models/HocPhan.php');
	include_once('Configs/paging.php');
    include_once('Models/HocKiNamHoc.php');
    include_once('Models/HPMoVaoHKNH.php');
    include_once('Models/LopHocPhan.php');
    include_once('Models/ThoiKhoaBieu.php');
?>

<form name="xepthoikhoabieu" method="POST">
<table align="center" class="font" width="800" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td class=main_1><img border="0" src="Libraries/images/tbl_left.gif" width="10" height="25" /></td>
    <td align=center class=main_1>Xếp Thời Khóa Biểu Lớp Học Phần </td>
    <td class=main_1><p align="right"><img border="0" src="Libraries/images/tbl_right.gif" width="10" height="25" /></p></td>
  </tr>
  <tr bgcolor="#dae9f3">
    <td class="border_1" colspan="3" valign="top"><table width="100%" border="0" align="center"  >
                <tr>
                    <td >&nbsp;</td>
                </tr>
                <tr>
                  <td align="center"><table border="0">
                      <tr>
                        <td>Năm học</td>
                        <td><select name="cbonamhoc" onchange="rangBuoc();">
                          <option value=" "></option>
                          <?php
								$hknh = new HocKiNamHoc();
                                $result = $hknh->dsNamHoc();
                                while ($rows=mysql_fetch_array($result)){
                                    echo "<option value='".$rows['namhoc']."'";				
				                    echo ">".$rows['namhoc']."</option>";
                                }
                                if (isset($_POST['cbonamhoc'])){
                                    echo "<script language=\"javascript\">for(var i=0;i<document.xepthoikhoabieu.cbonamhoc.length;i++){if(document.xepthoikhoabieu.cbonamhoc[i].value=='$namhoc'){document.xepthoikhoabieu.cbonamhoc.selectedIndex=i;break;}}</script>";
                                }
                                ?>
                        </select></td>
                        <td>Học kì</td>
                        <td><select name="cbohocki" onchange="hienThiHPTheoHKNH(document.xepthoikhoabieu.cbonamhoc.value,this.value);">
                          <option value="0"></option>
                          <option value="1" <?php if ($_POST['cbohocki']==1) echo "selected='selected'"; ?>>1</option>
                          <option value="2" <?php if ($_POST['cbohocki']==2) echo "selected='selected'"; ?>>2</option>
                          <option value="3" <?php if ($_POST['cbohocki']==3) echo "selected='selected'"; ?>>Hè</option>
                        </select></td>
                        <td><table border="0">
                          <tr>
                            <td>Học phần</td>
                            <td><?php  
                            
                                echo "<div id='hocphan'>";
                                    echo "<select name='cbohp' >";
                                        echo "<option value=' '></option>";                                 
                                    echo "</select>";
                                echo "</div>";
                            if (isset($_POST['cbohp'])){
                                   echo "<script language=\"javascript\">hienThiHPTheoHKNH('$namhoc','$hocki');</script>";
                                  
                             }
                        ?></td>
                          </tr>
                        </table></td>
                        <td>&nbsp;</td>
                      </tr>
                    </table></td>
                </tr>
                <tr>
                  <td align="center"><table border="0">
                    <tr>
                      <td><table border="0">
                        <tr>
                          <td>Nhóm</td>
                          <td><div id="lophp">
                              <select name="cbolophp">
                                <option value=""></option>
                              </select>
                          </div>
						  <?php
						  	if (isset($_POST['cbolophp'])){
                                    //echo "<script language=\"javascript\">hienThiDSLopHPCuaHPTrongHKNK('$namhoc','$hocki','$mahp')</script>";
                                  
                             }
						  ?>
						  </td>
                        </tr>
                      </table></td>
                      <td>Sĩ số </td>
                      <td><input name="txtsiso" type="text" size="4" readonly="true"/></td>
                      <td>Th&#7913;</td>
                      <td><select name="cbothu">
                        <option value="0"></option>
                        <option value="2">2</option>
                        <option value="3">3</option>
                        <option value="4">4</option>
                        <option value="5">5</option>
                        <option value="6">6</option>
                        <option value="7">7</option>
                        <option value="8">CN</option>
                      </select></td>
                      <td>Ti&#7871;t B&#272; </td>
                      <td><select name="cbotietbd">
                        <option value="0"></option>
                        <option value="1">1</option>
                        <option value="2">2</option>
                        <option value="3">3</option>
                        <option value="4">4</option>
                        <option value="5">5</option>
                        <option value="6">6</option>
                        <option value="7">7</option>
                        <option value="8">8</option>
                        <option value="9">9</option>
                        <option value="10">10</option>
                      </select></td>
                      <td>S&#7889; ti&#7871;t </td>
                      <td><select name="cbosotiet" onchange="xepPhong(document.xepthoikhoabieu.cbohocki.value,document.xepthoikhoabieu.cbonamhoc.value,document.xepthoikhoabieu.txtsiso.value,document.xepthoikhoabieu.cbothu.value,document.xepthoikhoabieu.cbotietbd.value,this.value);">
                        <option value="0"></option>
                        <option value="1">1</option>
                        <option value="2">2</option>
                        <option value="3">3</option>
                        <option value="4">4</option>
                        <option value="5">5</option>
                      </select></td>
                      <td><table border="0">
                        <tr>
                          <td>Ph&ograve;ng</td>
                          <td><div id="maphong">
                            <select name="cbomaphong">
                              <option value=" "></option>
                            </select>
                          </div></td>
                        </tr>
                      </table></td>
                    </tr>
                  </table></td>
                </tr>
                <tr>
          	        <td align="center"><label><span class="main_3">
          	          <input name="btnxem" type="submit" class="button_1" id="btnthem2" value="Xem"/>
          	          <input name="btnthem" type="submit" class="button_1" id="btnthem" value="Thêm"/>
                      <input name="btnxoa" type="submit"  class="button_1" id="btnxoa" value="Xóa"/>
                      <input name="btntrove" type="button"  class="button_1" id="btntrove" value="Trở về" onclick="history.go(-1)"/>
       	          </span></label></td>
                </tr>
                <tr>
       	          <td align="center">&nbsp;</td>
                </tr>
        </table>
       
           

    </td>
  </tr>
</table>
<br />
<?php
	
	if (isset($_POST['btnxem'])){
            
            if (isset($_POST['cbonamhoc'])){
                                   /* echo "<script language=\"javascript\">for(var i=0;i<document.xepthoikhoabieu.cbohp.length;i++){if(document.xepthoikhoabieu.cbohp[i].value=='$mahp'){document.xepthoikhoabieu.cbohp.selectedIndex=i;break;}}</script>";*/
                                }
            ?>
<table align="center" class="font" width="800" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td class="main_1"><img border="0" src="Libraries/images/tbl_left.gif" width="10" height="25" /></td>
    <td align="center" class="main_1">Thời Khóa Biểu Lớp HP:<?php echo $malophp?></td>
    <td class="main_1"><p align="right"><img border="0" src="Libraries/images/tbl_right.gif" width="10" height="25" /></p></td>
  </tr>
  <tr >
    <td class="border_1" colspan="3" valign="top"><table width="800" class="border_1" style="border:none" id="tbmain" cellpadding="0" cellspacing="0">
        <?php
			$db = new database();
			$db->setQuery("select a.mahp,kihieu, tenhp, maso,siso from HocPhan a, LopHocPhan b where malophp='".$malophp."' and a.mahp=b.mahp");
			$resultlophp = $db->fetchAll();
			$rowslophp = mysql_fetch_array($resultlophp);
			$tenhp = $rowslophp['tenhp'];
			$kihieu = $rowslophp['kihieu'];
			$siso = $rowslophp['siso'];
             $tkb = new ThoiKhoaBieu();
             $tkb->setMaLopHP($malophp);
             $resulttkb = $tkb->thoiKhoaBieuLopHP();
             $numtkb = mysql_num_rows($resulttkb);
             if ($numtkb > 0){ $i = 0;
        ?>
                  <tr>
                    <td align="center" width="30" class="main_3" >Thứ</td>
					<td align="center" width="30" class="main_3" >Mã HP</td>
					<td align="center" width="30" class="main_3" >KH</td>
					<td align="center" width="200" class="main_3" >Tên Học Phần</td>
					<td align="center" width="30" class="main_3" >Si Số</td>
                    <td align="center" class="main_3" width="60">Ti&#7871;t B&#272; </td>
                    <td align="center" class="main_3" width="60">S&#7889; Ti&#7871;t </td>
                    <td align="center" class="main_3" width="60">Ph&ograve;ng</td>
                    
                  </tr>
                  <?php
                        
                  while ($rowstkb = mysql_fetch_array($resulttkb)){
                        $i++;
                        $ci = 2 - $i % 2;
                       echo "<tr>";
                           echo "<td align='center' class='level_1_$ci'><div id='thu$i'>".$rowstkb['thu']."</div></td>";
						    echo "<td align='center' class='level_1_$ci'><div id='mahp$i'>".$mahp."</div></td>";
							 echo "<td align='center' class='level_1_$ci'><div id='kihieu$i'>".$kihieu."</div></td>";
							 echo "<td align='center' class='level_1_$ci'><div id='tenhp$i'>".$tenhp."</div></td>";
							 echo "<td align='center' class='level_1_$ci'><div id='siso$i'>".$siso."</div></td>";
                           echo "<td width='60' align='center' class='level_1_$ci'><div id='tietbd$i'>".$rowstkb['tietbd']."</div></td>";
                           echo "<td width='60' align='center' class='level_1_$ci'><div id='sotiet$i'>".$rowstkb['sotiet']."</div></td>";
                           echo "<td width='60' align='center' class='level_1_$ci'><div id='maphong$i'>".$rowstkb['maphong']."</div></td>";
                           //echo "<td align='center' class='level_1_$ci'><input type='radio' name='chkchon' value='$i'  onclick='getValue(this.value);'></td>";
                      echo "</tr>";
                  }
            }
            else{
                echo "<tr>";
                    echo "<td width='30' align='center' colspan='7'><b>Chưa sắp Thời khóa biểu</b></td>";
                                                
                                                
                echo "</tr>";
            }
      ?>
    </table></td>
  </tr>
</table>
<?php
    }
?>

 

</form>
